/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package interfaz;

import VO.Datos;
import VO.VariablesAmbientales;
import control.HelperValidar;
import control.ControlReportes;
import java.util.ArrayList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
/**
 *
 * @author giannin
 */
public class InterfazPrincipal extends javax.swing.JFrame {
    
    public static ArrayList<VariablesAmbientales> datos;
    
    /**
     * Creates new form InterfazPrincipal
     */
    public InterfazPrincipal() {
        datos = Datos.getContenido();
        initComponents();
        cambiarPanel(new FormularioDatos());
        this.setLocationRelativeTo(null);
    }
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        panelInterfaz = new javax.swing.JPanel();
        jRadioButton1 = new javax.swing.JRadioButton();
        jRadioButton2 = new javax.swing.JRadioButton();
        jRadioButton3 = new javax.swing.JRadioButton();
        jRadioButton4 = new javax.swing.JRadioButton();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        buttonExit = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        panelInterfaz.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 123, 0)));

        javax.swing.GroupLayout panelInterfazLayout = new javax.swing.GroupLayout(panelInterfaz);
        panelInterfaz.setLayout(panelInterfazLayout);
        panelInterfazLayout.setHorizontalGroup(
            panelInterfazLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 488, Short.MAX_VALUE)
        );
        panelInterfazLayout.setVerticalGroup(
            panelInterfazLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 550, Short.MAX_VALUE)
        );

        buttonGroup1.add(jRadioButton1);
        jRadioButton1.setSelected(true);
        jRadioButton1.setText("Registrar Valores");
        jRadioButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                registrarValorClick(evt);
            }
        });

        buttonGroup1.add(jRadioButton2);
        jRadioButton2.setText("Histórico de Resultados");
        jRadioButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                HistoricoClick(evt);
            }
        });

        buttonGroup1.add(jRadioButton3);
        jRadioButton3.setText("Valor Actual");
        jRadioButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                valorActualClick(evt);
            }
        });

        buttonGroup1.add(jRadioButton4);
        jRadioButton4.setText("Reporte");
        jRadioButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                reporteClick(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Ubuntu", 0, 18));
        jLabel1.setText("Central Meteorológica");

        jLabel2.setFont(new java.awt.Font("Ubuntu", 0, 18));
        jLabel2.setText("AguasCalientes");

        buttonExit.setText("SALIR");
        buttonExit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonExitActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jRadioButton1)
                            .addComponent(jRadioButton2)
                            .addComponent(jRadioButton3)
                            .addComponent(jRadioButton4)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(29, 29, 29)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel2)
                            .addComponent(jLabel1)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(35, 35, 35)
                        .addComponent(buttonExit, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panelInterfaz, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(panelInterfaz, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(52, 52, 52)
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(51, 51, 51)
                        .addComponent(jRadioButton1)
                        .addGap(18, 18, 18)
                        .addComponent(jRadioButton2)
                        .addGap(18, 18, 18)
                        .addComponent(jRadioButton3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jRadioButton4)
                        .addGap(49, 49, 49)
                        .addComponent(buttonExit, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void registrarValorClick(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_registrarValorClick
        cambiarPanel(new FormularioDatos());
    }//GEN-LAST:event_registrarValorClick

    private void HistoricoClick(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_HistoricoClick
        
        if(HelperValidar.validarExistencia()) 
          cambiarPanel(new Historico());
        else {
          JOptionPane.showMessageDialog(this, "Datos inexistentes!! por favor Introduzca los datos primero", "ERROR", JOptionPane.ERROR_MESSAGE);
          jRadioButton2.setSelected(false);
          jRadioButton1.setSelected(true);
        }
    }//GEN-LAST:event_HistoricoClick

    private void valorActualClick(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_valorActualClick
        if(HelperValidar.validarExistencia()) 
          cambiarPanel(new panelValorActual());
        else {
          JOptionPane.showMessageDialog(this, "Datos inexistentes!! por favor Introduzca los datos primero", "ERROR", JOptionPane.ERROR_MESSAGE);
          jRadioButton3.setSelected(false);
          jRadioButton1.setSelected(true);
        }
    }//GEN-LAST:event_valorActualClick

    private void reporteClick(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_reporteClick

        if(HelperValidar.validarExistencia()) 
          cambiarPanel(new panelReporte());
        else {
          JOptionPane.showMessageDialog(this, "Datos inexistentes!! por favor Introduzca los datos primero", "ERROR", JOptionPane.ERROR_MESSAGE);
          jRadioButton2.setSelected(false);
          jRadioButton1.setSelected(true);
        }
    }//GEN-LAST:event_reporteClick

private void buttonExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonExitActionPerformed
   System.exit(0);
}//GEN-LAST:event_buttonExitActionPerformed
    
    private void cambiarPanel(JPanel panel){
        panelInterfaz.setVisible(false);
        panelInterfaz.removeAll();
        panelInterfaz.setLayout(new java.awt.GridLayout(1, 0));
        panelInterfaz.add(panel);
        panelInterfaz.setVisible(true);
    }
    /**
     * @param args the command line arguments
     */
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton buttonExit;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JRadioButton jRadioButton1;
    private javax.swing.JRadioButton jRadioButton2;
    private javax.swing.JRadioButton jRadioButton3;
    private javax.swing.JRadioButton jRadioButton4;
    private javax.swing.JPanel panelInterfaz;
    // End of variables declaration//GEN-END:variables
}
